package com.example.cloud.controller.business.medical;

import com.example.cloud.controller.common.BaseController;
import com.example.cloud.model.business.medical.Allergen;
import com.example.cloud.model.dto.QueryModel;
import com.example.cloud.model.dto.Result;
import com.example.cloud.service.business.medical.AllergenService;
import com.example.cloud.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created by wangtao on 2018/7/2.
 */
@RestController
@RequestMapping("/allergen")
public class AllergenController extends BaseController {

    @Autowired
    private AllergenService allergenService;

    @PostMapping("/search")
    public Result search(@RequestBody QueryModel model) {
        return this.singleQuery(model, Allergen.class);
    }

    @GetMapping("/findById/{id}")
    public Result findById(@PathVariable Long id){
        return ResultUtil.success(allergenService.findOne(id));
    }

    @PostMapping("/saveOrUpdate")
    public void saveOrUpdate(@RequestBody Allergen record) {
        allergenService.doSave(record);
    }

    @PostMapping("/delete")
    public void delete(@RequestBody List<Long> ids){
        allergenService.doDelete(ids);
    }
}
